<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jsp/pub/include.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>用户管理</title>
    <link href="<%=request.getContextPath() %>/css/admin.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/common.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.form.js"></script>
    <script type="text/javascript">

        function show(id){
            var msg = "您真的确定要删除吗？\n\n请确认！";
            if (confirm(msg)==true){
             var  url=getRootPath()+"/user/deluser?m=del&id="+id;
              $.ajax({
                type:"GET",
                url: url,
                success:function(returndata){
                    var rdata = returndata;
                    alert(rdata.data.message);
                    if(rdata.data.suc){
                        window.location.href= getRootPath()+"/user/manage?m=list";
                    }else{
                        alert(rdata.data.message);
                    }
                }
            });
            }
        }
        function del(id){

          location=getRootPath()+"/user/deluser?m=del&id="+id;
//            $.ajax({
//                cache:false,
//                type:"GET",
//                url: url,
//                error:function(XMLHttpRequest, textStatus, errorThrown) {
//                    alert(XMLHttpRequest.status);
//                },
//                success:function(returndata){
//                    if(returndata.data.suc){
//                        window.location.href= getRootPath()+"/admin/index";
//                    }else{
//                        alert(returndata.data.message);
//                    }
//                }
//            });
        }
        function search(){

            var key = $("#key").val();
            var url = "<c:url value="/user/manage?m=list"/>";
            if(key!=""){
                url+="&key="+key;
            }

            location=url;
        }
        function addproject(){

            var url = "<c:url value="/user/manage?m=add"/>";
            location=url;
        }
        function downexcel(){

            location='${downexcel}';
        }

        function changeselect(){
            var url='<c:url value="/user/manage?m=list"/>';

            if($("#permission").val()!=""){
                url+='&permission='+$("#permission").val();
            }
            location=url;
        }
    </script>
</head>
<body>
<div class="content">
    <jsp:include page="../pub/top.jsp"></jsp:include>
    <!--头部结束-->
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="left" valign="top">
                <jsp:include page="../pub/left_user.jsp"></jsp:include>
            </td>
            <td valign="top">
                <div id="c01">
                    <dl>
                        <dt style="padding-right:30px;">操作权限：
                            <select class="sheng" name="permission" id="permission"  onchange="changeselect()">
                                <option value="0">选择操作权限</option>
                                <c:forEach items="${fsTypeList}" var="permission">
                                    <option value="${permission.code}" ${permission.code==param.permission?'selected=selected':''}><c:out value="${permission.value}"/></option>
                                </c:forEach>
                            </select>

                        </dt>
                        <dt >名字:<input type="text" class="key" id="key" name="key"/> </dt>
                        <dd style="padding-right:30px;"><input type="button" value="查询" class="chaxun" onclick="search()"/></dd>
                        <c:if test="${sessionScope.user.permission.code=='1'}">
                             <dd ><input type="button" value="新增员工" class="chaxun" onclick="addproject()"/></dd>
                        </c:if>

                        <dd style="margin-left:50px;padding-right:30px;"><input type="button" value="下载名单"  class="chaxun" onclick="downexcel()"/></dd>
                    </dl>
                    <table width="99%" border="0" cellpadding="0" cellspacing="1" bgcolor="#dae2e5">
                        <tr>
                            <td width="5%" height="30" bgcolor="#e5edfa" align="center">序号</td>
                            <td width="10%" height="30" bgcolor="#e5edfa" align="center" >名字</td>
                            <td width="15%" height="30" bgcolor="#e5edfa" align="center">所属部门</td>
                            <td width="10%" height="30" bgcolor="#e5edfa" align="center">职务</td>
                            <td width="15%" height="30" bgcolor="#e5edfa" align="center" >电话</td>
                            <td width="15%" height="30" bgcolor="#e5edfa" align="center">邮箱</td>
                            <td width="10%" height="30" bgcolor="#e5edfa" align="center">操作权限</td>
                            <td width="15%" height="30" bgcolor="#e5edfa" align="center">操作选项</td>
                        </tr>
                        <c:choose>
                            <c:when test="${not empty userList}">
                                <c:forEach items="${userList}" var="user" varStatus="vs">
                                    <tr>
                                        <td height="30" bgcolor="#FFFFFF" align="center">
                                            <input type="hidden" name="id" value="${user.id}"/>
                                            <c:out value="${vs.index+1}"/></td>
                                        <td height="30" bgcolor="#FFFFFF" align="center" style="color: #cc0000">
                                                <c:out value="${user.username}"/>
                                        </td>
                                        <td height="30" bgcolor="#FFFFFF" align="center" style="padding-left:10px;">
                                            <c:out value="${user.department}"/>
                                                <%--<a href="<c:url value="/clazz/view.do?id=${clazz.id}"/>" target="_blank"><c:out value="${clazz.name}"/></a>--%>
                                        </td>
                                        <td height="30" bgcolor="#FFFFFF" align="center" style="padding-left:10px;">
                                            <c:out value="${user.position}"/>
                                                <%--<a href="<c:url value="/clazz/view.do?id=${clazz.id}"/>" target="_blank"><c:out value="${clazz.name}"/></a>--%>
                                        </td>
                                        <td height="30" bgcolor="#FFFFFF" align="center" style="padding-left:10px;">
                                            <c:out value="${user.phone}"/>
                                                <%--<a href="<c:url value="/clazz/view.do?id=${clazz.id}"/>" target="_blank"><c:out value="${clazz.name}"/></a>--%>
                                        </td>
                                        <td height="30" bgcolor="#FFFFFF" align="center">
                                            <c:out value="${user.email}"/>
                                                <%--<c:out value="${clazz.industry}"/>--%>
                                        </td>
                                        <td height="30" bgcolor="#FFFFFF" align="center">
                                            <c:out value="${user.permission.value}"/>
                                                <%--<c:out value="${clazz.price}"/>--%>
                                        </td>
                                        <td  height="30" bgcolor="#FFFFFF" align="center">
                                            <c:if test="${sessionScope.user.permission.code=='1' || sessionScope.user.id == user.id}">
                                            <a href="<c:url value="/user/manage?m=edit&id=${user.id}"/>">修改</a>
                                            </c:if>
                                            <c:if test="${sessionScope.user.permission.code=='1'}">
                                            <%--<a  href="javascript:del('${user.id}')">删除</a>--%>
                                                <a href="javascript:void(0)" onclick="show('${user.id}')">删除</a>
                                            </c:if>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <tr>
                                    <td colspan="8" height="30" bgcolor="#ffffff" align="center">暂无数据</td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                    </table>
                    <jsp:include page="/WEB-INF/jsp/pub/page.jsp"></jsp:include>
                    <%--<p><input type="checkbox" onclick="selectAll(this)"/> 全选 --%>
                    <%--<input type="button" value="删除" class="shanchu" onclick="del(0)"/></p>--%>
                    <%--<jsp:include page="/WEB-INF/jsp/pub/page.jsp"></jsp:include>--%>
                </div>
                <br />
                <br />
            </td>
        </tr>
    </table>
    <jsp:include page="../pub/foot.jsp"></jsp:include>
</div>
</body>
</html>
